package user_private_key

import (
	"chain_bridge_service/internal/code"
	"chain_bridge_service/internal/pkg/core"
	"chain_bridge_service/internal/pkg/validation"
	"net/http"
)

type deleteAPIRequest struct {
	Id string `uri:"id"` // HashID
}

func (h *handler) Delete() core.HandlerFunc {
	return func(ctx core.Context) {
		req := new(deleteAPIRequest)
		res := new(createResponse)
		if err := ctx.ShouldBindURI(req); err != nil {
			ctx.AbortWithError(core.Error(
				http.StatusOK,
				code.ParamBindError,
				validation.Error(err)).WithError(err),
			)
			return
		}
		err := h.keyService.Delete(ctx, req.Id)
		if err != nil {
			ctx.AbortWithError(core.Error(
				http.StatusOK,
				code.UserPrivateKeyUpdateError,
				code.Text(code.UserPrivateKeyUpdateError)).WithError(err),
			)
			return
		}

		res.Code = code.StatusOK
		res.Data = nil
		res.Msg = code.Text(code.StatusOK)
		ctx.Payload(res)
	}
}
